package com.eastfair.auth.controller;

import com.eastfair.auth.dto.OrganizationDTO;
import com.eastfair.auth.entity.Organization;
import com.eastfair.auth.enumeration.OrganizationOrgTypeEnum;
import com.eastfair.auth.enumeration.ResourceOrganizationResourceTypeEnum;
import com.eastfair.auth.service.CompanyOrganizationService;
import com.eastfair.auth.service.ExhibitionOrganizationService;
import com.eastfair.auth.service.OrganizationService;
import com.eastfair.auth.service.ProjectOrganizationService;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 展商controlelr
 *
 * </p>
 *
 * @author ligang
 * @date 2021-09-07
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionOrganization")
@Api(value = "exhibitionOrganization", tags = "")
public class ExhibitionOrganizationController {


    @Autowired
    ExhibitionOrganizationService exhibitionOrganizationService;

    /**
     * 创建展会
     *
     * @param organizationDTO 实体
     *        orgType 节点类型
     *        name 节点名称
     *        parentId 父级节点id
     *        resourceId 资源id
     *        resourceType 资源类型
     * @return
     */
    @ApiOperation(value = "创建展会", notes = "创建展会")
    @PostMapping("/createExhibition")
    public R<Organization> createExhibition(@RequestBody @Validated({OrganizationDTO.createExhibition.class }) OrganizationDTO organizationDTO) {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return exhibitionOrganizationService.createExhibition(organizationDTO);
    }



    /**
     * 修改展会
     *
     * @param organizationDTO 实体
     *        orgType 节点类型
     *        name 节点名称
     *        parentId 父级节点id
     *        resourceId 资源id
     *        resourceType 资源类型
     * @return
     */
    @ApiOperation(value = "修改展会", notes = "修改展会")
    @PostMapping("/updExhibition")
    public R<Organization> updExhibition(@RequestBody OrganizationDTO organizationDTO) {
        return exhibitionOrganizationService.updExhibition(organizationDTO);
    }
    /**
     * 添加公司到展商
     *
     * @param organizationDTO 组织节点实体
     *              name 公司名称
     *              resourceId 公司资源id
     *              targetResourceId  目标资源id，如会展id
     * @return
     */
    @ApiOperation(value = "添加公司到展商", notes = "添加公司到展商")
    @PostMapping("/addCompany")
    public R addCompany(@RequestBody @Validated({OrganizationDTO.addCompanyExhibition.class }) OrganizationDTO organizationDTO) {
        return exhibitionOrganizationService.addCompany(organizationDTO,organizationDTO.getTargetResourceId());
    }


    /**
     * 剔除展商下的公司
     * @param organizationDTO 组织节点实体
     *             resourceId 公司资源id
     *             targetResourceId  目标资源id，如会展id
     *
     * @return
     */
    @ApiOperation(value = "剔除展商下的公司", notes = "剔除展商下的公司")
    @PostMapping("/removeCompany")
    public R removeCompany(@RequestBody @Validated({OrganizationDTO.removeCompany.class }) OrganizationDTO organizationDTO) {
        return exhibitionOrganizationService.removeCompany(organizationDTO,organizationDTO.getTargetResourceId());
    }

    /**
     * 剔除公司的展商员工
     * @param organizationDTO 实体
     *          resourceId 资源id
     *          userIds 剔除用户id
     * @return
     */
    @ApiOperation(value = "剔除公司的展商员工", notes = "剔除公司的展商员工")
    @PostMapping("/removeUseridOfExhibitionCompany")
    public R removeUseridOfExhibitionCompany(@RequestBody OrganizationDTO organizationDTO) {
        return exhibitionOrganizationService.removeUseridOfExhibitionCompany(organizationDTO.getResourceId(),organizationDTO.getUserIds());
    }

    /**
     * 添加公司的展商员工
     * @param organizationDTO 实体
     *          resourceId 资源id
     *          userIds 用户id
     * @return
     */
    @ApiOperation(value = "添加公司的展商员工", notes = "添加公司的展商员工")
    @PostMapping("/addUseridOfExhibitionCompany")
    public R addUseridOfExhibitionCompany(@RequestBody OrganizationDTO organizationDTO) {
        return exhibitionOrganizationService.addUseridOfExhibitionCompany(organizationDTO.getResourceId(),organizationDTO.getUserIds());
    }
}
